package HomeWork2;

public class PolymorphicDemo {
    public static void main(String[] args) {
        Animal[]animals=new Animal[5];
        animals[0]=new Dog("小白",5,"白");
        animals[1]=new Dog("小黑",2,"黑");
        animals[2]=new Fish("小绿",1,"绿");
        animals[3]=new Chick("小黄",4,"黄");
        animals[4]=new Fish("小彩",2,"彩");
        for (int i=0;i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            if (animals[i] instanceof Dog){
                ((Dog) animals[i]).lookHome();
            }
            if (animals[i] instanceof Chick){
                ((Chick) animals[i]).layEggs();
            }
            if (animals[i] instanceof Swim){
                ((Swim) animals[i]).swim();
            }
        }
        System.out.println();

        Master master=new Master();
        Dog dog=new Dog("小白",5,"白");
        Chick chick=new Chick("小黄",4,"黄");
        Fish fish=new Fish("小彩",2,"彩");
        master.feed(dog);
        master.feed(chick);
        master.feed(fish);
    }
}
